﻿using CatUtils.Utils.Currency;
using CatUtils.Utils.Currency.IoUtils;
using System;
using System.Collections.Generic;
using System.Drawing;

namespace LineStickerDwonload.Helper
{
    internal class ImgHelper
    {
        /// <summary>
        /// 背景转换为白色 批量
        /// </summary>
        /// <param name="FileList"></param>
        public void BackGroundToWrite(List<string> FileList)
        {
            foreach (var item in FileList)
            {
                BackGroundToWrite(item);
            }
        }

        /// <summary>
        /// 处理背景为白色
        /// </summary>
        /// <param name="FilePath"></param>
        public void BackGroundToWrite(string FilePath)
        {
            try
            {
                using (Bitmap bitmap = new Bitmap(FilePath))
                {
                    for (int i = 0; i < bitmap.Width; i++)
                    {
                        for (int j = 0; j < bitmap.Height; j++)
                        {
                            Color GetPixelColor = bitmap.GetPixel(i, j);
                            if (GetPixelColor.R == 76 && GetPixelColor.B == 113 && GetPixelColor.G == 105)
                            {
                                bitmap.SetPixel(i, j, Color.FromArgb(255, Color.White));
                            }
                        }
                    }
                    bitmap.Save(FileNameHelper.CreateFileNameWithChildFloder(FilePath, LineStaticValue.ImgClearTip), System.Drawing.Imaging.ImageFormat.Png);
                }
            }
            catch (Exception ex)
            {
                PrintLog.Log(ex);
            }
        }
    }
}